/**
 * Created by ss on 16/4/10.
 */
var $ = require('jquery');
var init = require('../util/init.js');
var util = require('../util/util.js');
var templateUtil = require('../util/templateUtil.js');
var mapUtil = require('../util/mapUtil.js');
require('../../scss/map.scss');
var ip = "115.193.53.158";
var port = 8000;

init.init();
var urlGet = util.urlGet();
var sender = JSON.parse(localStorage.getItem('sender'));
var map = mapUtil.init('baiduMap', 15, sender.longitude, sender.latitude);
var addRandom = function(map, num, bg, size){
    var bounds = map.getBounds();
    var lngSpan = bounds.Ee - bounds.Je;
    var latSpan = bounds.De - bounds.Ie;
    for(var i = 0; i < num; i++) {
        var point = new BMap.Point(bounds.Je + lngSpan * (Math.random() * 0.7 + 0.15),
            bounds.Ie + latSpan * (Math.random() * 0.7 + 0.15));
        mapUtil.addOverlay(map, point, bg, size);
    }
};
mapUtil.addOverlay(map, new BMap.Point(sender.longitude, sender.latitude), "http://d3.freep.cn/3tb_1605051043105wge564060.png", new BMap.Size(50,50));
addRandom(map, 3, "http://d3.freep.cn/3tb_160505104333dr7x564060.png", new BMap.Size(50,50));

$("#confirm").click(function () {
    map.setZoom(20);
    var dom = util.showLoading();
    var post = {
        receiver: encodeURIComponent(localStorage.getItem("receiver")),
        sender: encodeURIComponent(localStorage.getItem("sender")),
        type: localStorage.getItem("type"),
        sendType: localStorage.getItem("sendType")
    };
    $.post(util.getAjaxUrl("/addSend"), post).then(function (data) {
        dom.remove();
        if(data.code == 1) {
            localStorage.removeItem("receiver");
            localStorage.removeItem("sender");
            localStorage.removeItem("type");
            localStorage.removeItem("sendType");
            $("body").append("<img src='http://"+ip+":"+port+"'/>");
            util.changePage("./sendList");
        } else {
            alert(data.errorInfo);
        }
    });
});
$("#returnButton").click(function () {
    history.back();
})







